package com.sys.orders.service.impl;

import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sys.common.pojo.ApiResponse;
import com.sys.common.pojo.ApiResponseEnum;
import com.sys.common.pojo.JSONEnum;
import com.sys.common.util.ConstatFinalUtil;
import com.sys.common.util.PageInfoUtil;
import com.sys.goods.pojo.AAddress;
import com.sys.goods.pojo.ABlindbox;
import com.sys.goods.pojo.AGoods;
import com.sys.goods.pojo.AGoodsEnum;
import com.sys.goods.service.IGoodsDbService;
import com.sys.orders.dao.IAOrdersComment;
import com.sys.orders.dao.IAOrdersDeliver;
import com.sys.orders.dao.IAOrdersDesc;
import com.sys.orders.dao.IAOrdersGoods;
import com.sys.orders.pojo.AOrdersComment;
import com.sys.orders.pojo.AOrdersDeliver;
import com.sys.orders.pojo.AOrdersDeliverEnum;
import com.sys.orders.pojo.AOrdersDesc;
import com.sys.orders.pojo.AOrdersDescEnum;
import com.sys.orders.pojo.AOrdersGoods;
import com.sys.orders.pojo.AOrdersGoodsEnum;
import com.sys.orders.service.IOrdersDbService;
import com.sys.users.pojo.ACart;
import com.sys.users.pojo.ACartEnum;
import com.sys.users.pojo.AUsersEnum;
import com.sys.users.service.IUsersDbService;

/**
 * 订单的实现类
 * 
 * @author MyJjh
 *
 */
@Service("ordersDbService")
public class OrderDbServiceImpl implements IOrdersDbService
{
	@Autowired
	private IAOrdersComment ordersCommentDao;
	@Autowired
	private IAOrdersDeliver ordersDeliverDao;
	@Autowired
	private IAOrdersDesc ordersDescDao;
	@Autowired
	private IAOrdersGoods ordersGoodsDao;
	@Autowired
	private IUsersDbService usersDbService;
	@Autowired
	private IGoodsDbService goodsDbService;

	@Override
	public ApiResponse<Object> saveOneAOrdersCommentService(AOrdersComment orderscomment)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();

		orderscomment.setCommentTime(new Date());
		orderscomment.setCreateTime(new Date());
		orderscomment.setUpdateTime(new Date());
		orderscomment.setPubTime(new Date());
		orderscomment.setStatus(Byte.valueOf("1"));

		int res = this.ordersCommentDao.save(orderscomment);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), orderscomment.getCommentId());
			apiResponse.setDataOne(dataMap);
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneAOrdersCommentService(AOrdersComment orderscomment)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 查询条件 */
		orderscomment.setUpdateTime(new Date());
		int res = this.ordersCommentDao.update(orderscomment);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), orderscomment.getCommentId());
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneAOrdersCommentService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.ordersCommentDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<AOrdersComment> findOneAOrdersCommentService(Map<String, Object> condMap)
	{
		ApiResponse<AOrdersComment> apiResponse = new ApiResponse<AOrdersComment>();

		Map<String, AOrdersComment> data = new HashMap<String, AOrdersComment>();
		AOrdersComment ordersComment = this.ordersCommentDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), ordersComment);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */

		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(ordersComment);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<AOrdersComment> findCondListAOrdersCommentService(PageInfoUtil pageInfoUtil,
			Map<String, Object> condMap)
	{
		ApiResponse<AOrdersComment> apiResponse = new ApiResponse<AOrdersComment>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<AOrdersComment> demoOrdersCommentList = Collections.EMPTY_LIST;

		Map<String, List<AOrdersComment>> dataList = new HashMap<String, List<AOrdersComment>>();
		
		if (pageInfoUtil != null)
		{
			Page<Object> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			demoOrdersCommentList = this.ordersCommentDao.findCondList(condMap);
			pageInfoUtil.setTotalRecord(Long.valueOf(page.getTotal()).intValue());
		} else
		{
			demoOrdersCommentList = this.ordersCommentDao.findCondList(condMap);
		}

		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), demoOrdersCommentList);

		apiResponse.setPageInfoUtil(pageInfoUtil);
		apiResponse.setDataListJava(demoOrdersCommentList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> saveOneOrdersDeliverService(AOrdersDeliver ordersdeliver)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();

		ordersdeliver.setCreateTime(new Date());
		ordersdeliver.setUpdateTime(new Date());
		ordersdeliver.setPubTime(new Date());
		ordersdeliver.setStatus(Byte.valueOf("1"));

		int res = this.ordersDeliverDao.save(ordersdeliver);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), ordersdeliver.getDeliveryDetailsId());
			apiResponse.setDataOne(dataMap);
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneOrdersDeliverService(AOrdersDeliver ordersdeliver)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 查询条件 */
		ordersdeliver.setUpdateTime(new Date());
		int res = this.ordersDeliverDao.update(ordersdeliver);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), ordersdeliver.getDeliveryDetailsId());
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneOrdersDeliverService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.ordersDeliverDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<AOrdersDeliver> findOneOrdersDeliverService(Map<String, Object> condMap)
	{
		ApiResponse<AOrdersDeliver> apiResponse = new ApiResponse<AOrdersDeliver>();

		Map<String, AOrdersDeliver> data = new HashMap<String, AOrdersDeliver>();
		AOrdersDeliver ordersDeliver = this.ordersDeliverDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), ordersDeliver);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */

		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(ordersDeliver);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<AOrdersDeliver> findCondListOrdersDeliverService(PageInfoUtil pageInfoUtil,
			Map<String, Object> condMap)
	{
		ApiResponse<AOrdersDeliver> apiResponse = new ApiResponse<AOrdersDeliver>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<AOrdersDeliver> demoOrdersDeliverList = Collections.EMPTY_LIST;

		Map<String, List<AOrdersDeliver>> dataList = new HashMap<String, List<AOrdersDeliver>>();
		if (pageInfoUtil != null)
		{
			Page<Object> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			demoOrdersDeliverList = this.ordersDeliverDao.findCondList(condMap);
			pageInfoUtil.setTotalRecord(Long.valueOf(page.getTotal()).intValue());
		} else
		{
			demoOrdersDeliverList = this.ordersDeliverDao.findCondList(condMap);
		}

		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), demoOrdersDeliverList);

		apiResponse.setPageInfoUtil(pageInfoUtil);
		apiResponse.setDataListJava(demoOrdersDeliverList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> saveOneOrdersDescService(AOrdersDesc ordersdesc)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		Map<String, Object> condMap = new HashMap<String, Object>();
		/* 为收货人设置信息 */
		condMap.put("addressId", ordersdesc.getAddressId());
		ApiResponse<AAddress> addressApiResponse = this.goodsDbService.findOneAAddressService(condMap);
		AAddress address = addressApiResponse.getDataOneJava();
		ordersdesc.setConsigneeTelephone(address.getConsigneeNumber());
		ordersdesc.setConsigneeName(address.getConsigneeName());
		
		ordersdesc.setOrderDate(new Date());
		ordersdesc.setCreateTime(new Date());
		ordersdesc.setUpdateTime(new Date());
		ordersdesc.setPubTime(new Date());

		int res = this.ordersDescDao.save(ordersdesc);
		if (res > 0)
		{
			double totalPrice = 0 ; 
			/* 搜索条件,生成公共的搜索条件 */
			condMap.clear();
			/* 查询我的,查询启用的购物车 */
			condMap.put("usersId", ordersdesc.getUserId());
			condMap.put("status", AUsersEnum.STATUS_ENABLE.getStatus());
			/* 查询数据库
			 * 所有的数据以JSON的形式返回
			 *  */
			ApiResponse<ACart> cartApiResponse = this.usersDbService.findCondListCartService(null, condMap);
			List<ACart> cartList = cartApiResponse.getDataListJava();
			/* 将结果存储到Request中 */
			
			/* 存储订单明细 */
			for (Iterator iterator = cartList.iterator(); iterator.hasNext();)
			{
				ACart cart = (ACart) iterator.next();
				ABlindbox goods = cart.getBlindbox() ; 
				
				AOrdersGoods ordersGoods = new AOrdersGoods();
				ordersGoods.setOrderId(ordersdesc.getOrderId());
				ordersGoods.setBlindBoxId(goods.getBlindBoxId());
				
				ordersGoods.setSettlementPrice(goods.getBlindBoxPrices());
				ordersGoods.setGoodsQuantity(cart.getPurchaseQuantity());

				double totalPriceTemp = ordersGoods.getSettlementPrice() * ordersGoods.getGoodsQuantity();
				
				/* 总价格相加 */
				totalPrice = totalPrice + totalPriceTemp ; 
				
				ordersGoods.setStatus(AOrdersGoodsEnum.STATUS_ENABLE.getStatus());
				
				ordersGoods.setPubTime(new Date());
				/* 订单商品 */
				this.saveOneOrdersGoodsService(ordersGoods);
				
				cart.setPurchaseQuantity(0);
				cart.setStatus(ACartEnum.STATUS_DISABLED.getStatus());
				cart.setUpdateTime(new Date());
				
				/* 清空购物车 */
				this.usersDbService.updateOneCartService(cart);
				
				/* 更新商品的销量 */
				goods.setUpdateTime(new Date());
				goods.setBlindBoxNumber(goods.getBlindBoxNumber() - cart.getPurchaseQuantity());
				this.goodsDbService.updateOneABlindboxService(goods);
			}
			
			/* 设置总价格 */
			ordersdesc.setOrderAmount(totalPrice);
			/* 更新订单 */
			this.ordersDescDao.update(ordersdesc);
			
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), ordersdesc.getOrderId());
			apiResponse.setDataOne(dataMap);
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneOrdersDescService(AOrdersDesc ordersdesc)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		Map<String,Object> condMap = new HashMap<String, Object>();
		PageInfoUtil pageInfoUtil = new PageInfoUtil();
		/* 查询条件 */
		ordersdesc.setUpdateTime(new Date());
		int res = this.ordersDescDao.update(ordersdesc);
		if (res > 0)
		{
			/* 如果状态为已发货,直接更新发货记录 */
			if(ordersdesc.getOrderStatus() == AOrdersDescEnum.STATUS_YGOODS.getStatus()) {
				/* 查询所有的ordersGoods */
				condMap.clear();
				condMap.put("orderId", ordersdesc.getOrderId());
				ApiResponse<AOrdersGoods> ordersGoodsApiResponse = this.findCondListAOrdersGoodsService(null, condMap);
				List<AOrdersGoods> ordersGoodsList = ordersGoodsApiResponse.getDataListJava();
				for (AOrdersGoods ordersGoods : ordersGoodsList) {
					/* 判断它需要的数量
					 * 生成发货记录
					 *  */
					pageInfoUtil.setCurrentPage(1);
					pageInfoUtil.setPageSize(ordersGoods.getGoodsQuantity());
					condMap.put("status", AGoodsEnum.STATUS_ENABLE.getStatus());
					ApiResponse<AGoods> goodsListApiResponse = this.goodsDbService.findCondListAGoodsService(pageInfoUtil, condMap);
					List<AGoods> goodsList = goodsListApiResponse.getDataListJava();
					for (AGoods goods : goodsList) {
						AOrdersDeliver deliver = new AOrdersDeliver();
						deliver.setBlindBoxId(goods.getGoodsId());
						deliver.setOrderDetailsId(ordersGoods.getOrderDetailsId());
						deliver.setPurchaseQuantity(1);
						deliver.setStatus(AOrdersDeliverEnum.STATUS_ONE.getStatus());
						this.saveOneOrdersDeliverService(deliver);
						
						goods.setStatus(AGoodsEnum.STATUS_DISABLED.getStatus());
						this.goodsDbService.updateOneAGoodsService(goods);
					}
				}
			}
			
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), ordersdesc.getOrderId());
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneOrdersDescService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.ordersGoodsDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<AOrdersDesc> findCondListOrdersDescService(PageInfoUtil pageInfoUtil,
			Map<String, Object> condMap)
	{
		ApiResponse<AOrdersDesc> apiResponse = new ApiResponse<AOrdersDesc>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<AOrdersDesc> demoOrdersDescList = Collections.EMPTY_LIST;

		Map<String, List<AOrdersDesc>> dataList = new HashMap<String, List<AOrdersDesc>>();
		if (pageInfoUtil != null)
		{
			Page<Object> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			demoOrdersDescList = this.ordersDescDao.findCondList(condMap);
			pageInfoUtil.setTotalRecord(Long.valueOf(page.getTotal()).intValue());
		} else
		{
			demoOrdersDescList = this.ordersDescDao.findCondList(condMap);
		}

		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), demoOrdersDescList);

		apiResponse.setPageInfoUtil(pageInfoUtil);
		apiResponse.setDataListJava(demoOrdersDescList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<AOrdersDesc> findOneOrdersDescService(Map<String, Object> condMap)
	{
		ApiResponse<AOrdersDesc> apiResponse = new ApiResponse<AOrdersDesc>();

		Map<String, AOrdersDesc> data = new HashMap<String, AOrdersDesc>();
		AOrdersDesc ordersDesc = this.ordersDescDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), ordersDesc);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */

		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(ordersDesc);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> saveOneOrdersGoodsService(AOrdersGoods ordersgoods)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();

		ordersgoods.setCreateTime(new Date());
		ordersgoods.setUpdateTime(new Date());
		ordersgoods.setPubTime(new Date());
		ordersgoods.setStatus(Byte.valueOf("1"));

		int res = this.ordersGoodsDao.save(ordersgoods);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), ordersgoods.getOrderDetailsId());
			apiResponse.setDataOne(dataMap);
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneOrdersGoodsService(AOrdersGoods ordersgoods)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 查询条件 */
		ordersgoods.setUpdateTime(new Date());
		int res = this.ordersGoodsDao.update(ordersgoods);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), ordersgoods.getOrderId());
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneAOrdersGoodsAdminsService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.ordersGoodsDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<AOrdersGoods> findOneAOrdersGoodsService(Map<String, Object> condMap)
	{
		ApiResponse<AOrdersGoods> apiResponse = new ApiResponse<AOrdersGoods>();

		Map<String, AOrdersGoods> data = new HashMap<String, AOrdersGoods>();
		AOrdersGoods ordersDeliver = this.ordersGoodsDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), ordersDeliver);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */

		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(ordersDeliver);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<AOrdersGoods> findCondListAOrdersGoodsService(PageInfoUtil pageInfoUtil,
			Map<String, Object> condMap)
	{
		ApiResponse<AOrdersGoods> apiResponse = new ApiResponse<AOrdersGoods>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<AOrdersGoods> demoOrdersGoodsList = Collections.EMPTY_LIST;

		Map<String, List<AOrdersGoods>> dataList = new HashMap<String, List<AOrdersGoods>>();
		if (pageInfoUtil != null)
		{
			Page<Object> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			demoOrdersGoodsList = this.ordersGoodsDao.findCondList(condMap);
			pageInfoUtil.setTotalRecord(Long.valueOf(page.getTotal()).intValue());
		} else
		{
			demoOrdersGoodsList = this.ordersGoodsDao.findCondList(condMap);
		}
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), demoOrdersGoodsList);

		apiResponse.setPageInfoUtil(pageInfoUtil);
		apiResponse.setDataListJava(demoOrdersGoodsList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

}
